\documentclass{article}

\usepackage{comment}
\usepackage{alltt}
\usepackage{amssymb}


\begin{document}
\author{Stephen Tetley}
\title{SuperCollider field notes}
\maketitle

%-----------------------------------------------------------------



%-----------------------------------------------------------------
\section{The interpreter}
%-----------------------------------------------------------------


SuperCollider defines 26 variables that are accessible at the 
top-level - one for each of the lowercase letters. 

\texttt{g} and \texttt{s} are already defined with \texttt{s} 
being the server instance and \texttt{g} being the GUI.

%-----------------------------------------------------------------
\section{Functional programming}
%-----------------------------------------------------------------

SuperCollider has first class functions and a light-weight 
notation to define them, functions are defined inside braces with
the argument list delimited by bars:

\begin{verbatim}
// The id function
i = {|a| a};
i.value(4);
\end{verbatim}

\begin{verbatim}
// The const function
c = {|a b| a};
c.value(4,5);
\end{verbatim}

Functions can be partially applied to fewer arguments than they 
accept this produces a new function:

\begin{verbatim}
// Partial application
c = max(_,10);
c.value(5);
\end{verbatim}

Likewise for operators:

\begin{verbatim}
c = (_ + 2);
c.value(2);
\end{verbatim}



SuperCollider's \texttt{do} is not equivalent to the common 
\emph{map} operation in functional languages, instead use 
\texttt{collect}.


Don't gratuitously use functions inside if statements.


\texttt{do} is analogue to Scheme's \texttt{foreach}, it is used 
to iterate a side-effecting operation over a collection, returning
the receiver. Iterating a pure function with \texttt{do} leaves 
the receiver unchanged. 

\texttt{collect} returns the results of evaluating the iteration.

SuperCollider has wildcards that allow a lightweight functional 
notation. Wildcards can be sent messages just like named objects:

\begin{verbatim}
(1..5).select(_.even);
\end{verbatim}

% Note, alltt appears to lack the fontshapes for braces
As oppposed to
\begin{verbatim}
(1..5).select({ arg x; x.even });
\end{verbatim}


\texttt{sort} subsumes Haskell's \texttt{sort} and 
\texttt{sortBy} - omit a comparison function to sort with the 
\texttt{<} operator.

Dictionaries are collections of \emph{Associations} - Associations 
are objects independent of Dictionaries, they are constructed with
special arrow syntax \texttt{->}:

\begin{verbatim}
(\monkey -> 99).value.postln;
\end{verbatim}


%-----------------------------------------------------------------
\section{Classes}

To find where to store classes so they are visible to 
SuperCollider, evalute this line:

\begin{verbatim}
Platform.userExtensionDir
\end{verbatim}

Caret designates a return statement in a method declaration.

Sending objects the \texttt{dump} message will print some 
\emph{diagnostic} information.

%-----------------------------------------------------------------

\end{document}
